package com.hcrazy.manchester.app.controllers;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.hcrazy.manchester.app.pojo.Attachment;
import com.hcrazy.manchester.app.pojo.ErrorMsg;
import com.hcrazy.manchester.app.pojo.Group;
import com.hcrazy.manchester.app.pojo.GroupUser;
import com.hcrazy.manchester.app.pojo.LiveCommon;
import com.hcrazy.manchester.app.pojo.LiveSort;
import com.hcrazy.manchester.app.pojo.PageModel;
import com.hcrazy.manchester.app.pojo.Rent;
import com.hcrazy.manchester.app.pojo.Secondary;
import com.hcrazy.manchester.app.pojo.SecondaryRequire;
import com.hcrazy.manchester.app.pojo.Topic;
import com.hcrazy.manchester.app.pojo.User;
import com.hcrazy.manchester.app.pojo.UserInfo;
import com.hcrazy.manchester.app.services.AttachmentService;
import com.hcrazy.manchester.app.services.CityService;
import com.hcrazy.manchester.app.services.ForumService;
import com.hcrazy.manchester.app.services.GroupService;
import com.hcrazy.manchester.app.services.LiveSortService;
import com.hcrazy.manchester.app.services.RentService;
import com.hcrazy.manchester.app.services.SecondaryRequireService;
import com.hcrazy.manchester.app.services.SecondaryService;
import com.hcrazy.manchester.app.services.TopicService;
import com.hcrazy.manchester.app.services.UserService;
import com.hcrazy.manchester.app.utils.Constant;
import com.hcrazy.manchester.app.utils.Constant.Views;
import com.hcrazy.manchester.app.utils.Log;

@Controller
@RequestMapping("/api")
public class APIController {

	@Autowired
	private LiveSortService liveSortService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private TopicService topicService;
	
	@Autowired
	private ForumService forumService;
	
	@Autowired
	private RentService rentService;
	
	@Autowired
	private SecondaryService secondaryService;
	
	@Autowired
	private SecondaryRequireService secondaryRequireService;
	
	@Autowired
	private AttachmentService attachmentService;
	
	@Autowired
	private GroupService groupService;
	
	@Autowired
	private CityService cityService;
	
	/**********************************************************************************
	 * 生活信息部分
	 **********************************************************************************/
	@RequestMapping(value="/live/sorts",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody List<LiveSort> getAllLiveSorts(@RequestParam(required=false) Integer parentId){
		try {
			if(null == parentId){
				return liveSortService.getAllSorts(Constant.TYPE_LIVE,0);
			}else{
				return liveSortService.getAllSorts(Constant.TYPE_LIVE,parentId);
			}
			
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return null;
		}
	}
	
	/**
	 * 获取全部信息列表
	 * @param sortId
	 * @param hasDetail
	 * @return
	 */
	@RequestMapping(value="/live/infos",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody LiveSort getAllInfos(@RequestParam int sortId,@RequestParam(required=false) Integer hasDetail){
		try {
			if(null == hasDetail || hasDetail == Constant.INFO_NO_DETAIL){
				return liveSortService.getLiveSortWithInfos(sortId,false);
			}else if(hasDetail == Constant.INFO_HAS_DETAIL){
				return liveSortService.getLiveSortWithInfos(sortId,true);
			}
			return null;
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return null;
		}
	}
	

	/**
	 * 获取全部信息列表(常用信息)
	 * @param sortId
	 * @param hasDetail
	 * @return
	 */
	@RequestMapping(value="/live/infos/common",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody List<LiveCommon> getAllCommonInfos(@RequestParam(required=false) Integer sortId){
		try {
			if(null == sortId)
				sortId = 0;
			return liveSortService.getCommonInfos(sortId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return null;
		}
	}
	
	@RequestMapping(value="/live/info",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getInfo(
			@RequestParam int infoId,
			@RequestParam(required=false) Integer hasDetail,
			@RequestParam int sortId){
		try {
			if(null == hasDetail || hasDetail == Constant.INFO_NO_DETAIL){
				return liveSortService.getInfoById(infoId, sortId, false);
			}else if(hasDetail == Constant.INFO_HAS_DETAIL){
				return liveSortService.getInfoById(infoId, sortId, true);
			}
			return null;
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return null;
		}
	}
	
	@RequestMapping(value="/live/info/details",method=RequestMethod.GET,produces={MediaType.APPLICATION_JSON_VALUE,MediaType.TEXT_PLAIN_VALUE})
	public @ResponseBody Object getInfoDetails(
			@RequestParam int infoId,
			@RequestParam int sortId){
		try {
			Object o = liveSortService.getInfoDetails(infoId, sortId);
			return setResult(o.toString());
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return null;
		}
	}
	
	/************************生活信息部分end******************************************************/
	
	
	/***********************************************************************************
	 * 会员部分start
	 ***********************************************************************************/
	
	/**
	 * 会员注册
	 * @param user
	 * @param validateCode
	 * @return
	 */
	@RequestMapping(value="/register",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object register(
			@RequestBody User user, 
			HttpServletRequest req){
		ErrorMsg msg = new ErrorMsg();
		//判断验证码是否正确
		Object validateCode = req.getSession().getAttribute("validateCode");
		UserInfo userInfo = new UserInfo();
		try {
			return userService.register(user, validateCode);
		} catch (Exception e) {
			e.printStackTrace();
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/**
	 * 会员登录
	 * @param username
	 * @param password
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/login",method=RequestMethod.POST)
	public @ResponseBody Object login(
			@RequestParam String username,
			@RequestParam String password,
			HttpServletRequest req){
		
		try {
			Object obj = userService.login(username, password);
			if(obj instanceof User){
				((User)obj).setJsessionId(req.getSession().getId());
				req.getSession().setAttribute("user",obj);
			}
			return obj;
			
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	
	}
	
	@RequestMapping(value="/logout",method={RequestMethod.POST,RequestMethod.GET})
	public @ResponseBody Object logout(
			HttpServletRequest req){
		
		try {
			req.getSession().setAttribute("user",null);
			req.getSession().invalidate();
			return setResult("true");
			
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	
	}
	
	private Map<String,String> setResult(String value){
		Map<String,String> result = new HashMap<String,String>();
		result.put(Constant.SINGLE_RETURN,value);
		return result;
	}
	
	/**
	 * 完善用户详细资料
	 * @param userInfo
	 * @param map
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/user/info",method={RequestMethod.POST})
	public @ResponseBody Object updateUserInfo(
			@RequestBody UserInfo userInfo,
			ModelMap map,
			HttpServletRequest req){
		try {
			//获取当前登录用户
			Object obj = req.getSession().getAttribute("user");
			if(null == obj){
				return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
			}
			User user = (User)obj;
			userInfo.setUserId(user.getUserId());
			
			userService.updateUserInfo(userInfo);
			//更新，将之前返回true全部改为json
			
			return setResult("true");
			
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	
	}
	
	@RequestMapping(value="/user/password",method={RequestMethod.POST,RequestMethod.GET})
	public @ResponseBody Object updatePassword(
			@RequestParam String oldPassword,
			@RequestParam String newPassword,
			ModelMap map,
			HttpServletRequest req){
		try {
			//获取当前登录用户
			Object obj = req.getSession().getAttribute("user");
			if(null == obj){
				return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
			}
			User user = (User)obj;
			
			return userService.changePassword(user.getUserId(), oldPassword, newPassword);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	
	}
	
	/*@RequestMapping(value="/user/password/find",method={RequestMethod.POST,RequestMethod.GET})
	public @ResponseBody Object findPassword(
			@RequestParam String info){
		try {
			
			return userService.changePassword(user.getUserId(), oldPassword, newPassword);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	
	}*/
	
	/**
	 * 设置头像
	 * @param file
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/user/header", method = RequestMethod.POST)
	public @ResponseBody Object fileUpload(@RequestParam("file") CommonsMultipartFile file, HttpServletRequest req) {

		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		User user = (User)obj;
		long userId = user.getUserId();
		if (!file.isEmpty()) {

			String path = req.getSession().getServletContext().getRealPath("/resources/fileupload/header");
			String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
			String name = UUID.randomUUID().toString();
			String filePath = path + File.separator + name + suffix;

			File saveFile = new File(filePath);

			try {
				file.getFileItem().write(saveFile);
				String finalname = name + suffix;
				//保存至数据库
				userService.updateHeader(finalname, userId);
				return setResult(finalname);
			} catch (Exception e) {
				Log.error(e.getMessage(), e);
				return null;
			}

		}

		return null;

	}
	
	/**
	 * 获取用户详细资料
	 * @param userId
	 * @param map
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/user/info/{userId}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getUserInfo(
			@PathVariable("userId") long userId,
			ModelMap map){
		try {
			return userService.getUserInfo(userId);
			
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	
	}
	
	@RequestMapping(value="/user/info",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getLoginUserInfo(
			HttpServletRequest req){
		try {
			//获取当前登录用户
			Object obj = req.getSession().getAttribute("user");
			if(null == obj || !(obj instanceof User)){
				return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
			}
			long userId = ((User)obj).getUserId();
			return userService.getUserInfo(userId);
			
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	
	}
	
	/**
	 * 批量增加好友
	 * @param friends
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/user/friends",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object addFirends(
			@RequestParam String friends,
			HttpServletRequest req){
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		long userId = ((User)obj).getUserId();
		String userName = ((User)obj).getUsername();
		try {
			userService.addFriends(userId, userName, friends.split(","));
			return setResult("true");
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}		
	}
	
	/**
	 * 单个增加好友
	 * @param friendId
	 * @param message
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/user/friend",method={RequestMethod.POST,RequestMethod.GET},produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object addFirend(
			@RequestParam long friendId,
			@RequestParam String message,
			HttpServletRequest req){
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		long userId = ((User)obj).getUserId();
		String userName = ((User)obj).getUsername();
		try {
			userService.addFriend(userId, userName, friendId, message);
			return setResult("true");
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}		
	}
	
	@RequestMapping(value="/user/friends/allowed",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getAllowedFriends(HttpServletRequest req){
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		long userId = ((User)obj).getUserId();
		PageModel model = new PageModel();
		try {
			return userService.getAllowedFriends(userId,model);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/user/friends/apply",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getApplyFriends(HttpServletRequest req){
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		PageModel model = new PageModel();
		long userId = ((User)obj).getUserId();
		try {
			return userService.getApplyedFriends(userId,model);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/**
	 * 好友申请通过审核
	 * @param friendId
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/user/friend/allow",method={RequestMethod.POST,RequestMethod.GET},produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object setFirend(
			@RequestParam long friendId,
			HttpServletRequest req){
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		long userId = ((User)obj).getUserId();
		try {
			userService.setFriend(friendId, userId,Constant.USER_FRIEND_ALLOW);
			return setResult("true");
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}		
	}
	
	/**
	 * 好友申请审核拒绝
	 * @param friendId
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/user/friend/refuse",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object refuseFirend(
			@RequestParam long friendId,
			HttpServletRequest req){
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		long userId = ((User)obj).getUserId();
		try {
			userService.setFriend(userId, friendId,Constant.USER_FRIEND_REFUSE);
			return setResult("true");
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}		
	}
	
	/**
	 * 好友状态校验
	 * @param friendId
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/user/friend/check",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object checkFriend(
			@RequestParam long friendId,
			HttpServletRequest req){
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		long userId = ((User)obj).getUserId();
		try {
			String status = userService.checkFriend(userId, friendId);
			return setResult(status);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}		
	}
	
	@RequestMapping(value="/users/suggest/hometown/{homeTown}")
	public @ResponseBody Object getUsersByHomeTown(
			@PathVariable("homeTown") String homeTown,
			HttpServletRequest req){
		try {
			long userId = 0;
			//获取当前登录用户
			Object obj = req.getSession().getAttribute("user");
			if(null != obj && (obj instanceof User)){
				userId = ((User)obj).getUserId();
			}
			
			return userService.getUsersByHomeTown(homeTown,userId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}		
	}
	
	@RequestMapping(value="/users/suggest/school/{school}")
	public @ResponseBody Object getUsersBySchool(
			@PathVariable("school") int school,
			HttpServletRequest req){
		try {
			long userId = 0;
			//获取当前登录用户
			Object obj = req.getSession().getAttribute("user");
			if(null != obj && (obj instanceof User)){
				userId = ((User)obj).getUserId();
			}
			return userService.getUsersBySchool(school,userId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}		
	}
	
	/***********************************************************************************
	 * 会员部分end
	 ***********************************************************************************/
	
	
	/***********************************************************************************
	 * 论坛部分 开始
	 ***********************************************************************************/
	
	/**
	 * 获取论坛版块
	 * @return
	 */
	@RequestMapping(value="/forum/forums",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getAllForums(){
		try {
			return forumService.getAllForums();
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION, e.getMessage());
		}
	}
	
	/**
	 * 获取论坛相关主题列表
	 * @param forumId
	 * @param type
	 * @param pageNum （带分页参数）
	 * @return
	 */
	@RequestMapping(value="/forum/topics/{pageNum}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getAllTopics(
			@RequestParam int forumId,
			@RequestParam int type,
			@RequestParam(required = false) Integer forumType,//区分群组还是论坛
			@PathVariable("pageNum") int pageNum){
		PageModel pageModel = new PageModel();
		pageModel.setPageNum(pageNum);
		try {
			if(null == forumType){
				forumType = Constant.TYPE_FORUM;
			}
			return topicService.getTopics(pageModel, type, forumId,forumType);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	
	@RequestMapping(value="/forum/topics/hot",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody List<Topic> getHotTopics(){
		try {
			return topicService.getHotTopics(10);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return null;
			//return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/forum/topics/{pageNum}/{numPerPage}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getAllTopics(
			@RequestParam int forumId,
			@RequestParam int type,
			@RequestParam(required = false) Integer forumType,//区分群组还是论坛
			@PathVariable("pageNum") int pageNum,
			@PathVariable("numPerPage") int numPerPage){
		PageModel pageModel = new PageModel();
		pageModel.setPageNum(pageNum);
		pageModel.setNumPerPage(numPerPage);
		try {
			if(null == forumType){
				forumType = Constant.TYPE_FORUM;
			}
			return topicService.getTopics(pageModel, type, forumId,forumType);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/forum/topics",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getDefaultTopics(
			@RequestParam int forumId,
			@RequestParam(required = false) Integer forumType,//区分群组还是论坛
			@RequestParam int type){
		PageModel pageModel = new PageModel();
		try {
			if(null == forumType){
				forumType = Constant.TYPE_FORUM;
			}
			return topicService.getTopics(pageModel, type, forumId,forumType);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/**
	 * 获取全部约
	 * @param forumId
	 * @param forumType
	 * @param type
	 * @return
	 */
	@RequestMapping(value="/forum/appoints",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getAllAppoints(
			@RequestParam int type){
		PageModel pageModel = new PageModel();
		try {
			return topicService.getTopics(pageModel, type, Constant.FORUM_TYPE_APPOINT_ID,Constant.TYPE_FORUM);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/forum/mytopics/{pageNum}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getMyTopics(
			@PathVariable("pageNum") int pageNum,
			HttpServletRequest req){
		PageModel pageModel = new PageModel();
		pageModel.setPageNum(pageNum);
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		long userId = ((User)obj).getUserId();		
		try {
			return topicService.getMyTopics(pageModel, userId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/forum/mytopics/{pageNum}/{numPerPage}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getMyTopics(
			@PathVariable("pageNum") int pageNum,
			@PathVariable("numPerPage") int numPerPage,
			HttpServletRequest req){
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		long userId = ((User)obj).getUserId();			
		PageModel pageModel = new PageModel();
		pageModel.setPageNum(pageNum);
		pageModel.setNumPerPage(numPerPage);
		try {
			return topicService.getMyTopics(pageModel, userId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/forum/mytopics",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getMyTopics(
			HttpServletRequest req){
	
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		long userId = ((User)obj).getUserId();	
		
		PageModel pageModel = new PageModel();
		try {
			return topicService.getMyTopics(pageModel, userId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/forum/myposts/{pageNum}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getMyPosts(
			@PathVariable("pageNum") int pageNum,
			HttpServletRequest req){
		PageModel pageModel = new PageModel();
		pageModel.setPageNum(pageNum);
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		long userId = ((User)obj).getUserId();		
		try {
			return topicService.getMyPosts(pageModel, userId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/forum/myposts/{pageNum}/{numPerPage}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getMyPosts(
			@PathVariable("pageNum") int pageNum,
			@PathVariable("numPerPage") int numPerPage,
			HttpServletRequest req){
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		long userId = ((User)obj).getUserId();			
		PageModel pageModel = new PageModel();
		pageModel.setPageNum(pageNum);
		pageModel.setNumPerPage(numPerPage);
		try {
			return topicService.getMyPosts(pageModel, userId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/forum/myposts",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getMyPosts(
			HttpServletRequest req){
	
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj || !(obj instanceof User)){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		long userId = ((User)obj).getUserId();	
		
		PageModel pageModel = new PageModel();
		try {
			return topicService.getMyPosts(pageModel, userId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/**
	 * 获取某个论坛信息
	 * @param forumId
	 * @return
	 */
	@RequestMapping(value="/forum/forum",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getForum(@RequestParam int forumId){
		try {
			return forumService.getForumById(forumId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/**
	 * 发表主题
	 * @param topic
	 * @return
	 */
	@RequestMapping(value="/forum/topic",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object publishTopic(
			HttpServletRequest req,@RequestParam int forumId,
			@RequestParam(required = false) Integer type,
			@RequestParam(required = false) String images){
		try {
			//如果用户未登录，返回错误码
			Object obj = req.getSession().getAttribute("user");
			if(null == obj){
				return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，不允许发表主题！");
			}
			
			User user = (User)obj;
			String username = user.getUsername();
			long userId = user.getUserId();
			String userIp = req.getRemoteAddr();
			
			Topic topic = new Topic();
			topic.setForumId(forumId);
			topic.setSubject(req.getParameter("subject"));
			topic.setMessage(req.getParameter("message"));
			topic.setUserIp(userIp);
			topic.setAuthor(username);
			topic.setAuthorId(userId);
			topic.setImages(images);
			
			
			if(null != type && type == Constant.TYPE_GROUP)
				topic.setType(Constant.TYPE_GROUP);
			
			return topicService.addTopic(topic);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/**
	 * 浏览主题帖子
	 * @param topicId
	 * @return
	 */
	@RequestMapping(value="/forum/topic/{topicId}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object viewTopic(@PathVariable("topicId") long topicId){
		try {
			return topicService.viewTopic(topicId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/**
	 * 回帖
	 * @param forumId
	 * @param topicId
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/forum/post",method={RequestMethod.POST,RequestMethod.GET},produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object replyTopic(
			@RequestParam int forumId,
			@RequestParam long topicId,
			@RequestParam int anonymous,//是否允许匿名回复
			HttpServletRequest req){
		
		String username = "匿名用户";
		long userId = 0;
		if(anonymous == Constant.POST_ANONYMOUS_UN_ALLOWED){
			Object obj = req.getSession().getAttribute("user");
			if(null == obj){
				return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，不允许发表回复！");
			}
			User user = (User)obj;
			username = user.getUsername();
			userId = user.getUserId();
		}
		
		String userIp = req.getRemoteAddr();
		try {
			return topicService.replyTopic(topicId, forumId, req.getParameter("message"), username, userId, userIp,anonymous);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/***********************************************************************************
	 * 论坛部分 结束
	 ***********************************************************************************/
	
	
	/***********************************************************************************
	 * 实用功能部分 开始  （包括：租房、二手交易等）
	 ***********************************************************************************/
	
	/**
	 * 房屋出租信息查询
	 * @param rentType
	 * @param houseType
	 * @param status
	 * @param priceRange
	 * @param priceStart
	 * @param priceEnd
	 * @param roomRange
	 * @param keywords
	 * @param pageNum
	 * @param numPerPage
	 * @return
	 */
	@RequestMapping(value="/func/rents",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getRents(
			@RequestParam(required = false) Integer rentType,//出租方式，可选
			@RequestParam(required = false) Integer houseType,//房屋类型
			@RequestParam(required = false) Integer status,//房源类型（个人发布还是经纪人发布）
			@RequestParam(required = false) Integer priceRange,//价格区间
			@RequestParam(required = false) Integer priceStart,//自定义价格上限
			@RequestParam(required = false) Integer priceEnd,//自定义价格下限
			@RequestParam(required = false) Integer roomRange,//厅室
			@RequestParam(required = false) String keywords,//关键词搜索
			@RequestParam(required = false) Integer pageNum,//第几页
			@RequestParam(required = false) Integer numPerPage//一页请求多少条数据
			){
		PageModel pageModel = new PageModel();
		if(null != pageNum && pageNum > 0){
			pageModel.setPageNum(pageNum);
		}
		if(null != numPerPage && numPerPage > 0){
			pageModel.setNumPerPage(numPerPage);
		}
		rentType = (null == rentType)?0:rentType;
		houseType = (null == houseType)?0:houseType;
		status = (null == status)?0:status;
		priceRange = (null == priceRange)?0:priceRange;
		priceStart = (null == priceStart)?0:priceStart;
		priceEnd = (null == priceEnd)?0:priceEnd;
		roomRange = (null == roomRange)?0:roomRange;
		keywords = (null == keywords)?"":keywords;
		
		try {
			return rentService.getRents(pageModel, keywords, 0,Constant.RENT_TYPE_TO_RENT,rentType, houseType, status, priceRange, priceStart, priceEnd, roomRange);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/func/require/rents",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getRequireRents(
			@RequestParam(required = false) Integer rentType,//出租方式，可选
			@RequestParam(required = false) Integer houseType,//房屋类型
			@RequestParam(required = false) Integer priceRange,//价格区间
			@RequestParam(required = false) Integer priceStart,//自定义价格上限
			@RequestParam(required = false) Integer priceEnd,//自定义价格下限
			@RequestParam(required = false) Integer roomRange,//厅室
			@RequestParam(required = false) String keywords,//关键词搜索
			@RequestParam(required = false) Integer pageNum,//第几页
			@RequestParam(required = false) Integer numPerPage//一页请求多少条数据
			){
		PageModel pageModel = new PageModel();
		if(null != pageNum && pageNum > 0){
			pageModel.setPageNum(pageNum);
		}
		if(null != numPerPage && numPerPage > 0){
			pageModel.setNumPerPage(numPerPage);
		}
		rentType = (null == rentType)?0:rentType;
		houseType = (null == houseType)?0:houseType;
		priceRange = (null == priceRange)?0:priceRange;
		priceStart = (null == priceStart)?0:priceStart;
		priceEnd = (null == priceEnd)?0:priceEnd;
		roomRange = (null == roomRange)?0:roomRange;
		keywords = (null == keywords)?"":keywords;
		
		try {
			return rentService.getRents(pageModel, keywords, 0,Constant.RENT_TYPE_FOR_RENT,rentType, houseType, 0, priceRange, priceStart, priceEnd, roomRange);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/func/myrents",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getUserRents(
			HttpServletRequest req,
			@RequestParam(required = false) Integer rentType,//出租方式，可选
			@RequestParam(required = false) Integer houseType,//房屋类型
			@RequestParam(required = false) Integer status,//房源类型（个人发布还是经纪人发布）
			@RequestParam(required = false) Integer priceRange,//价格区间
			@RequestParam(required = false) Integer priceStart,//自定义价格上限
			@RequestParam(required = false) Integer priceEnd,//自定义价格下限
			@RequestParam(required = false) Integer roomRange,//厅室
			@RequestParam(required = false) String keywords,//关键词搜索
			@RequestParam(required = false) Integer pageNum,//第几页
			@RequestParam(required = false) Integer numPerPage//一页请求多少条数据
			){
		
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，无权限访问！");
		}
		User user = (User)obj;
		
		PageModel pageModel = new PageModel();
		if(null != pageNum && pageNum > 0){
			pageModel.setPageNum(pageNum);
		}
		if(null != numPerPage && numPerPage > 0){
			pageModel.setNumPerPage(numPerPage);
		}
		rentType = (null == rentType)?0:rentType;
		houseType = (null == houseType)?0:houseType;
		status = (null == status)?0:status;
		priceRange = (null == priceRange)?0:priceRange;
		priceStart = (null == priceStart)?0:priceStart;
		priceEnd = (null == priceEnd)?0:priceEnd;
		roomRange = (null == roomRange)?0:roomRange;
		keywords = (null == keywords)?"":keywords;
		
		try {
			return rentService.getRents(pageModel, keywords, user.getUserId(),0,rentType, houseType, status, priceRange, priceStart, priceEnd, roomRange);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/func/my/require/rents",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getRequireRents(
			HttpServletRequest req,
			@RequestParam(required = false) Integer rentType,//出租方式，可选
			@RequestParam(required = false) Integer houseType,//房屋类型
			@RequestParam(required = false) Integer priceRange,//价格区间
			@RequestParam(required = false) Integer priceStart,//自定义价格上限
			@RequestParam(required = false) Integer priceEnd,//自定义价格下限
			@RequestParam(required = false) Integer roomRange,//厅室
			@RequestParam(required = false) String keywords,//关键词搜索
			@RequestParam(required = false) Integer pageNum,//第几页
			@RequestParam(required = false) Integer numPerPage//一页请求多少条数据
			){
		
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，无权限访问！");
		}
		User user = (User)obj;
		
		PageModel pageModel = new PageModel();
		if(null != pageNum && pageNum > 0){
			pageModel.setPageNum(pageNum);
		}
		if(null != numPerPage && numPerPage > 0){
			pageModel.setNumPerPage(numPerPage);
		}
		rentType = (null == rentType)?0:rentType;
		houseType = (null == houseType)?0:houseType;
		priceRange = (null == priceRange)?0:priceRange;
		priceStart = (null == priceStart)?0:priceStart;
		priceEnd = (null == priceEnd)?0:priceEnd;
		roomRange = (null == roomRange)?0:roomRange;
		keywords = (null == keywords)?"":keywords;
		
		try {
			return rentService.getRents(pageModel, keywords, user.getUserId(),Constant.RENT_TYPE_FOR_RENT,rentType, houseType, 0, priceRange, priceStart, priceEnd, roomRange);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/**
	 * 发布租房信息
	 * @param rent
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/func/rent",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object postRent(
    		@RequestBody Rent rent,
    		HttpServletRequest req){
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，不允许发布或更新！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		String userIp = req.getRemoteAddr();
		rent.setUserId(userId);
		rent.setRemoteIp(userIp);
		try {
			rentService.addOrUpdateRent(rent);
			Map<String,String> result = new HashMap<String,String>();
			result.put(Constant.SINGLE_RETURN,"true");
			return result;
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		
    }
	
	/**
	 * 发布求租信息
	 * @param rent
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/func/rent/require",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object postForRent(
    		@RequestBody Rent rent,
    		HttpServletRequest req){
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，不允许发布或更新！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		String userIp = req.getRemoteAddr();
		rent.setUserId(userId);
		rent.setRemoteIp(userIp);
		rent.setTheType(Constant.RENT_TYPE_FOR_RENT);
		try {
			rentService.addOrUpdateRent(rent);
			Map<String,String> result = new HashMap<String,String>();
			result.put(Constant.SINGLE_RETURN,"true");
			return result;
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		
    }
	
	/**
	 * 删除租房信息
	 * @param rent
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/func/rent/del/{rentId}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object delRent(
    		@PathVariable("rentId") long rentId,
    		HttpServletRequest req){
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，无权限访问！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		
		try {
			rentService.delRent(rentId,userId);
			Map<String,String> result = new HashMap<String,String>();
			result.put(Constant.SINGLE_RETURN,"true");
			return result;
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		
    }
	
	
	/**
	 * 二手交易分类
	 * @return
	 */
	@RequestMapping(value="/secondary/sorts",produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody List<LiveSort> getAllSecondarySorts(@RequestParam(required=false) Integer parentId){
		try {
			if(null == parentId)
				return liveSortService.getAllSorts(Constant.TYPE_FUNC,0);
			
			return liveSortService.getAllSorts(Constant.TYPE_FUNC,parentId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return null;
		}
	}
	
	
	@RequestMapping(value="/func/secondaries",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getSecondaries(
			@RequestParam(required = true) Integer sortId,//分类ID（大分类、小分类、直接分类、上级分类等等）
			@RequestParam(required = false) Integer status,//发布来源，个人还是商家
			@RequestParam(required = false) Integer priceRange,//价格区间
			@RequestParam(required = false) Integer priceStart,//自定义价格上限
			@RequestParam(required = false) Integer priceEnd,//自定义价格下限
			@RequestParam(required = false) String keywords,//关键词搜索
			@RequestParam(required = false) Integer pageNum,//第几页
			@RequestParam(required = false) Integer numPerPage//一页请求多少条数据
			){
		PageModel pageModel = new PageModel();
		if(null != pageNum && pageNum > 0){
			pageModel.setPageNum(pageNum);
		}
		if(null != numPerPage && numPerPage > 0){
			pageModel.setNumPerPage(numPerPage);
		}
		status = (null == status)?0:status;
		priceRange = (null == priceRange)?0:priceRange;
		priceStart = (null == priceStart)?0:priceStart;
		priceEnd = (null == priceEnd)?0:priceEnd;
		keywords = (null == keywords)?"":keywords;
		
		try {
			return secondaryService.getSecondaries(pageModel, sortId, status, priceRange, priceStart, priceEnd, keywords,0);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/func/require/secondaries",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getRequireSecondaries(
			@RequestParam(required = false) String keywords,//关键词搜索
			@RequestParam(required = false) Integer pageNum,//第几页
			@RequestParam(required = false) Integer numPerPage//一页请求多少条数据
			){
		PageModel pageModel = new PageModel();
		if(null != pageNum && pageNum > 0){
			pageModel.setPageNum(pageNum);
		}
		if(null != numPerPage && numPerPage > 0){
			pageModel.setNumPerPage(numPerPage);
		}
		keywords = (null == keywords)?"":keywords;
		
		try {
			return secondaryRequireService.getSecondaryInfos(pageModel, keywords, 0);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/func/mysecondaries",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getUserSecondaries(
			HttpServletRequest req,
			@RequestParam(required = false) Integer sortId,//分类ID（大分类、小分类、直接分类、上级分类等等）
			@RequestParam(required = false) Integer status,//发布来源，个人还是商家
			@RequestParam(required = false) Integer priceRange,//价格区间
			@RequestParam(required = false) Integer priceStart,//自定义价格上限
			@RequestParam(required = false) Integer priceEnd,//自定义价格下限
			@RequestParam(required = false) String keywords,//关键词搜索
			@RequestParam(required = false) Integer pageNum,//第几页
			@RequestParam(required = false) Integer numPerPage//一页请求多少条数据
			){
		
		//如果用户未登录，返回错误码
	
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，不允许发布或更新！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		
		PageModel pageModel = new PageModel();
		if(null != pageNum && pageNum > 0){
			pageModel.setPageNum(pageNum);
		}
		if(null != numPerPage && numPerPage > 0){
			pageModel.setNumPerPage(numPerPage);
		}
		
		sortId = (null == sortId)?0:sortId;
		status = (null == status)?0:status;
		priceRange = (null == priceRange)?0:priceRange;
		priceStart = (null == priceStart)?0:priceStart;
		priceEnd = (null == priceEnd)?0:priceEnd;
		keywords = (null == keywords)?"":keywords;
		
		try {
			return secondaryService.getSecondaries(pageModel, sortId, status, priceRange, priceStart, priceEnd, keywords,userId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/func/my/require/secondaries",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getMyRequireSecondaries(
			HttpServletRequest req,
			@RequestParam(required = false) String keywords,//关键词搜索
			@RequestParam(required = false) Integer pageNum,//第几页
			@RequestParam(required = false) Integer numPerPage//一页请求多少条数据
			){
		
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，不允许发布或更新！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		
		PageModel pageModel = new PageModel();
		if(null != pageNum && pageNum > 0){
			pageModel.setPageNum(pageNum);
		}
		if(null != numPerPage && numPerPage > 0){
			pageModel.setNumPerPage(numPerPage);
		}
		
		keywords = (null == keywords)?"":keywords;
		
		try {
			return secondaryRequireService.getSecondaryInfos(pageModel, keywords,userId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/**
	 * 发布或者更新二手交易信息
	 * @param rent
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/func/secondary",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object postSecondary(
    		@RequestBody Secondary secondary,
    		HttpServletRequest req){
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，不允许发布或更新！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		String userIp = req.getRemoteAddr();
		secondary.setUserId(userId);
		secondary.setRemoteIp(userIp);
		try {
			secondaryService.addOrUpdateSecondary(secondary);
			Map<String,String> result = new HashMap<String,String>();
			result.put(Constant.SINGLE_RETURN,"true");
			return result;
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		
    }
	
	/**
	 * 发布或者更新二手求购信息
	 * @param rent
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/func/secondary/require",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object postSecondaryRequire(
    		@RequestBody SecondaryRequire secondary,
    		HttpServletRequest req){
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，不允许发布或更新！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		String userIp = req.getRemoteAddr();
		secondary.setUserId(userId);
		secondary.setRemoteIp(userIp);
		secondary.setUsername(user.getUsername());
		try {
			secondaryRequireService.addOrUpdateSecondaryRequire(secondary);
			Map<String,String> result = new HashMap<String,String>();
			result.put(Constant.SINGLE_RETURN,"true");
			return result;
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		
    }
	
	/**
	 * 删除二手信息
	 * @param infoId
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/func/secondary/del/{infoId}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object delSecondary(
    		@PathVariable("infoId") long infoId,
    		HttpServletRequest req){
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，无权限访问！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		
		try {
			secondaryService.delSecondary(infoId,userId);
			Map<String,String> result = new HashMap<String,String>();
			result.put(Constant.SINGLE_RETURN,"true");
			return result;
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		
    }
	
	/**
	 * 删除二手求购信息
	 * @param infoId
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/func/secondary/require/del/{infoId}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object delSecondaryRequire(
    		@PathVariable("infoId") long infoId,
    		HttpServletRequest req){
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，无权限访问！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		
		try {
			secondaryRequireService.delSecondary(infoId,userId);
			Map<String,String> result = new HashMap<String,String>();
			result.put(Constant.SINGLE_RETURN,"true");
			return result;
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		
    }
	
	/**
	 * 增加浏览次数
	 * @param module
	 * @param id
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/info/views",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object setViews(
			@RequestParam String module,
			@RequestParam long id,
			HttpServletRequest req){
		
		try {
			if(!validate(req,Constant.OneDayViews,module,id)){
				Map<String,String> result = new HashMap<String,String>();
				result.put(Constant.SINGLE_RETURN,"同一IP或客户端在统一天内访问同一条信息不增加计数");
				return result;
			}
			
			if(module.equals("secondary")){
				secondaryService.setViews(id);
			}else if(module.equals("rent")){
				rentService.setViews(id);
			}else if(module.equals("topic")){
				topicService.setViews(id);
			}else{
				return new ErrorMsg(Constant.SET_VIEWS_ERROR,"模块名称:"+module+" 错误：");
			}
			
			Map<String,String> result = new HashMap<String,String>();
			result.put(Constant.SINGLE_RETURN,"true");
			return result;
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			Map<String,String> result = new HashMap<String,String>();
			result.put(Constant.SINGLE_RETURN,e.getMessage());
			return result;
		}
	}
	
	private boolean validate(HttpServletRequest req,Map<String,List<Views>> onDayViews,String module,long id){
		DateTime dt = new DateTime();
		String key = dt.toString("yyyy-MM-dd");
		String remoteIp = req.getRemoteAddr();
		Views views = new Views();
		views.setId(id);
		views.setModule(module);
		List<Views> list = new ArrayList<Views>();
		if(onDayViews.isEmpty()){
			views.getRemoteIps().add(remoteIp);
			list.add(views);
			onDayViews.put(key, list);
		}else{
			//同一天
			if(onDayViews.containsKey(key)){
				List<Views> vs = onDayViews.get(key);
				boolean has = false;
				for(Views v:vs){
					if(v.getId() == id && v.getModule().equals(module)){
						//同一个模块同一条数据
						for(String ip:v.getRemoteIps()){
							if(ip.equals(remoteIp)){
								//有相同的客户端ip，不增加计数
								return false;
							}
						}
						//新客户端，则存储客户端地址
						v.getRemoteIps().add(remoteIp);
						has = true;//存在该view
					}
				}
				//如果views不存在，则新增
				if(!has){
					views.getRemoteIps().add(remoteIp);
					vs.add(views);
					
				}
				
				
			}else{ //第二天
				onDayViews.clear();
				views.getRemoteIps().add(remoteIp);
				list.add(views);
				onDayViews.put(key, list);
			}
		
		}
		return true;
	}
	
	@RequestMapping(value="/user/college",method={RequestMethod.POST,RequestMethod.GET},produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object addCollege(
    		@RequestParam(required=true) Integer type,
    		@RequestParam(required=true) Integer infoId,
    		HttpServletRequest req){
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，无权限访问！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		
		try {
			userService.addCollege(userId, infoId, type);
			Map<String,String> result = new HashMap<String,String>();
			result.put(Constant.SINGLE_RETURN,"true");
			return result;
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		
    }
	
	@RequestMapping(value="/user/collection",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getCollection(HttpServletRequest req,@RequestParam int moduleType){
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，无权限访问！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		PageModel model = new PageModel();
		try {
			return userService.getUserColleges(userId,moduleType,model);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}		
	}
	
	@RequestMapping(value="/user/colleged",method={RequestMethod.GET,RequestMethod.POST},produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object isCollege(
    		@RequestParam(required=true) Integer type,
    		@RequestParam(required=true) Integer infoId,
    		HttpServletRequest req){
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，无权限访问！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		Map<String,Integer> result = new HashMap<String,Integer>();
		try {
			int count = userService.getCollegeCount(userId, infoId, type);
			if(count > 0){
				result.put(Constant.SINGLE_RETURN,1);
			}else{
				result.put(Constant.SINGLE_RETURN,0);
			}
			
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		
		return result;
    }
	
	@RequestMapping(value="/user/college/del",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object delCollege(
    		@RequestParam("infoId") long infoId,
    		@RequestParam("type") int type,
    		HttpServletRequest req){
		//如果用户未登录，返回错误码
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录，无权限访问！");
		}
		
		User user = (User)obj;
		long userId = user.getUserId();
		
		try {
			userService.deleteCollege(userId, infoId,type);
			Map<String,String> result = new HashMap<String,String>();
			result.put(Constant.SINGLE_RETURN,"true");
			return result;
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		
    }
	
	/***********************************************************************************
	 * 实用功能部分 结束
	 ***********************************************************************************/
	
	
	/***********************************************************************************
	 * 学术讨论部分 开始
	 ***********************************************************************************/
	
	/**
	 * 上传学习小组共享资料
	 * @param file
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/study/group/file", method = RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object shareFileUpload(
			@RequestParam long groupId,
			@RequestParam("file") CommonsMultipartFile file, 
			HttpServletRequest req) {
		//获取当前登录用户
		Object obj = req.getSession().getAttribute("user");
		if(null == obj){
			return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
		}
		
		User user = (User)obj;
		if (!file.isEmpty()) {
			
			String path = req.getSession().getServletContext().getRealPath("/resources/fileupload/study");
			String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
			String name = UUID.randomUUID().toString();
			String filePath = path + File.separator + name + suffix;

			File saveFile = new File(filePath);

			try {
				file.getFileItem().write(saveFile);
				String finalname = name + suffix;
				//保存至数据库
				Attachment attachment = new Attachment();
				attachment.setFileName(file.getOriginalFilename());
				attachment.setFile(finalname);
				attachment.setUsername(user.getUsername());
				attachment.setUid(user.getUserId());
				attachment.setForumId(groupId);
				attachmentService.addAttachment(attachment);
				return setResult(finalname);
			} catch (Exception e) {
				Log.error(e.getMessage(), e);
				return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
			}

		}

		return setResult("null");

	}
	
	/**
	 * 获取院系专业
	 * @return
	 */
	@RequestMapping(value="/study/faculties",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody List<LiveSort> getAllFaculties(@RequestParam(required=false) Integer parentId){
		
		try {
			if(null == parentId)
				return liveSortService.getAllSorts(Constant.TYPE_FACULTY,0);
			return liveSortService.getAllSorts(Constant.TYPE_FACULTY,parentId);
			
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return null;
		}
	} 
	
	@RequestMapping(value="/study/groups",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getGroups(
			@RequestParam(required = false) Integer sortId,//所属专业，可选
			@RequestParam(required = false) String keywords,//搜索关键词，可选
			@RequestParam(required = false) Integer pageNum,//第几页
			@RequestParam(required = false) Integer numPerPage//一页请求多少条数据
			){
		PageModel pageModel = new PageModel();
		if(null != pageNum && pageNum > 0){
			pageModel.setPageNum(pageNum);
		}
		if(null != numPerPage && numPerPage > 0){
			pageModel.setNumPerPage(numPerPage);
		}
		if(null == sortId){
			sortId = 0;
		}
		
		try {
			return groupService.getPagedInfos(pageModel, keywords, sortId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/**
	 * 创建学习小组
	 * @param
	 * @return
	 */
	@RequestMapping(value="/study/group",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object createGroup(@RequestBody Group group,
    		HttpServletRequest req){
		try {
			//获取当前登录用户
			Object obj = req.getSession().getAttribute("user");
			if(null == obj){
				return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
			}
			User user = (User)obj;
			group.setFounderUid(user.getUserId());
			group.setFounderName(user.getUsername());
			groupService.addOrUpdateGroup(group);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		return setResult("true");
    }

	@RequestMapping(value="/study/group/user",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object createGroup(
    		@RequestParam long groupId,
    		HttpServletRequest req){
		try {
			//获取当前登录用户
			Object obj = req.getSession().getAttribute("user");
			if(null == obj){
				return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
			}
			User user = (User)obj;
			GroupUser gUser = new GroupUser();
			gUser.setGroupId(groupId);
			gUser.setUserId(user.getUserId());
			gUser.setUsername(user.getUsername());
			
			groupService.addGroupUser(gUser);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		return setResult("true");
    }
	
	/**
	 * 批准或拒绝加入学习小组
	 * @param groupId
	 * @param userId
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/study/group/user/{allow}",method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Object allowJoinGroup(
    		@RequestParam long groupId,
    		@RequestParam long userId,
    		@PathVariable("allow") int allow,
    		HttpServletRequest req){
		try {
			//获取当前登录用户
			Object obj = req.getSession().getAttribute("user");
			if(null == obj){
				return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
			}
			if(allow == 1)
				groupService.apply(groupId, userId);
			else
				groupService.refuse(groupId, userId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
		return setResult("true");
    }
	
	/**
	 * 获取小组的成员列表
	 * @param groupId
	 * @return
	 */
	@RequestMapping(value="/study/group/users",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getJoinGroupUsers(@RequestParam long groupId,@RequestParam int status){
		try {
			return groupService.getGroupUsers(groupId,status);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/study/group/files",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getGroupFiles(
			@RequestParam long groupId,
			@RequestParam(required = false) Integer pageNum,//第几页
			@RequestParam(required = false) Integer numPerPage//一页请求多少条数据
			){
		PageModel pageModel = new PageModel();
		if(null != pageNum && pageNum > 0){
			pageModel.setPageNum(pageNum);
		}
		if(null != numPerPage && numPerPage > 0){
			pageModel.setNumPerPage(numPerPage);
		}
		try {
			return attachmentService.getAttachments(pageModel, groupId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/***********************************************************************************
	 * 学术讨论部分 结束
	 ***********************************************************************************/
	
	/***********************************************************************************
	 * 同城部分 开始
	 ***********************************************************************************/
	
	@RequestMapping(value="/cities",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getAllCities(){
		try {
			return cityService.getAllCities(false);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/hotCities",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getAllHotCities(){
		try {
			return cityService.getAllCities(true);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/cityMembers",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getAllCityMembers(int cityId){
		try {
			PageModel pageModel = new PageModel();
			return userService.getUserInfosByCityId(pageModel,cityId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/cityTopics",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getCityTopics(@RequestParam int cityId){
		
		PageModel pageModel = new PageModel();
		try {
			return topicService.getTopicsByCityId(pageModel, cityId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	@RequestMapping(value="/cityTopics/{pageNum}",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object getCityTopics(
			@PathVariable("pageNum") int pageNum,
			@RequestParam int cityId){
		PageModel pageModel = new PageModel();
		pageModel.setPageNum(pageNum);
			
		try {
			return topicService.getMyTopics(pageModel, cityId);
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	}
	
	/**
	 * 个人活动信息统计：我的消息数、我发布的帖子数、我回应的帖子数（消息）、我的收藏数
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/user/statistics",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
	public @ResponseBody Object statistics(HttpServletRequest req){
		try {
			//获取当前登录用户
			Object obj = req.getSession().getAttribute("user");
			if(null == obj){
				return new ErrorMsg(Constant.MEMBER_LOGIN_NOT,"会员未登录！");
			}
			User user = (User)obj;
			
			return userService.getStatistics(user.getUserId());
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
			return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
		}
	
	}
	
	/***********************************************************************************
	 * 同城部分 结束
	 ***********************************************************************************/
	
	@ExceptionHandler(Exception.class)
	public @ResponseBody ErrorMsg getException(Exception e){
		Log.error(e.getMessage(), e);
		return new ErrorMsg(Constant.ERROR_CODE_SYSTEM_EXCEPTION,e.getMessage());
	}
	
	
}
